/*****************************************************************************
 *  This file is part of the OpenDomo project.
 *  Copyright(C) 2012 OpenDomo Services SL
 *  
 *  Daniel Lerch Hostalot <dlerch@opendomo.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *****************************************************************************/



#include <gtk/gtk.h>
#include <string.h>
#include <stdlib.h>
#include <virtual_ports_widgets.h>

extern char p_ai[8][16];
extern char p_di[8][16];
extern char p_do[8][16];
extern char p_vt[16][16];

// {{{ cb_virtual_port_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_selector_activated(GtkWidget *w, 
	virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->type_selected, option, sizeof(data->type_selected));

	if(strstr(option, "Valor"))
	{
		gtk_widget_show(data->entry_v_value);
		gtk_widget_show(data->value_ad_opt);

		gtk_widget_hide(data->group_vp1_opt);
		gtk_widget_hide(data->group_vp2_opt);
   	gtk_widget_hide(data->group_op_opt);

   	gtk_widget_hide(data->trigger_cndp_opt);
   	gtk_widget_hide(data->trigger_outp_opt);
   	gtk_widget_hide(data->trigger_outval_opt);
   	gtk_widget_hide(data->trigger_cnd_opt);

		virtual_port_value_ad_select(data, "Digital");
	}
	else if(strstr(option, "Operación"))
	{
		virtual_port_group_vp1_select(data, "");
		virtual_port_group_vp2_select(data, "");

		gtk_widget_hide(data->entry_v_value);
		gtk_widget_hide(data->value_ad_opt);

		gtk_widget_show(data->group_vp1_opt);
		gtk_widget_show(data->group_vp2_opt);
   	gtk_widget_show(data->group_op_opt);

   	gtk_widget_hide(data->trigger_cndp_opt);
   	gtk_widget_hide(data->trigger_outp_opt);
   	gtk_widget_hide(data->trigger_outval_opt);
   	gtk_widget_hide(data->trigger_cnd_opt);

		virtual_port_group_vp1_select(data, p_di[0]);
		virtual_port_group_vp2_select(data, p_di[0]);
		virtual_port_group_op_select(data, "+");
	}
	else if(strstr(option, "Disparador"))
	{
		virtual_port_trigger_cndp_select(data, "");
		virtual_port_trigger_outp_select(data, "");

		gtk_widget_hide(data->entry_v_value);
		gtk_widget_hide(data->value_ad_opt);

		gtk_widget_hide(data->group_vp1_opt);
		gtk_widget_hide(data->group_vp2_opt);
   	gtk_widget_hide(data->group_op_opt);

   	gtk_widget_show(data->trigger_cndp_opt);
   	gtk_widget_show(data->trigger_outp_opt);
   	gtk_widget_show(data->trigger_outval_opt);
   	gtk_widget_show(data->trigger_cnd_opt);

		virtual_port_trigger_cnd_select(data, "==");
		virtual_port_trigger_cndp_select(data, p_di[0]);
		virtual_port_trigger_outp_select(data, p_do[0]);
		virtual_port_trigger_outval_select(data, "on");
	}
	else if(strstr(option, "--"))
	{
		gtk_widget_hide(data->entry_v_value);
		gtk_widget_hide(data->value_ad_opt);

		gtk_widget_hide(data->group_vp1_opt);
		gtk_widget_hide(data->group_vp2_opt);
   	gtk_widget_hide(data->group_op_opt);

   	gtk_widget_hide(data->trigger_cndp_opt);
   	gtk_widget_hide(data->trigger_outp_opt);
   	gtk_widget_hide(data->trigger_outval_opt);
   	gtk_widget_hide(data->trigger_cnd_opt);
	}

}
// }}}

// {{{ cb_virtual_port_value_ad_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_value_ad_selector_activated(GtkWidget *w, 
	virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->value_ad_selected, option, sizeof(data->value_ad_selected));
}
// }}}

// {{{ cb_virtual_port_group_vp1_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_group_vp1_selector_activated(GtkWidget *w, 
	virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->group_vp1_selected, option, sizeof(data->group_vp1_selected));
}
// }}}

// {{{ cb_virtual_port_group_vp2_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_group_vp2_selector_activated(GtkWidget *w, 
	virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->group_vp2_selected, option, sizeof(data->group_vp2_selected));
}
// }}}

// {{{ cb_virtual_port_group_op_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_group_op_selector_activated(GtkWidget *w, 
	virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->group_op_selected, option, sizeof(data->group_op_selected));
}
// }}}

// {{{ cb_virtual_port_trigger_cndp_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_trigger_cndp_selector_activated(
GtkWidget *w, virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->trigger_cndp_selected, option, 
		sizeof(data->trigger_cndp_selected));
}
// }}}

// {{{ cb_virtual_port_trigger_outp_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_trigger_outp_selector_activated(
GtkWidget *w, virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->trigger_outp_selected, option, 
		sizeof(data->trigger_outp_selected));
}
// }}}

// {{{ cb_virtual_port_trigger_outval_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_trigger_outval_selector_activated(
GtkWidget *w, virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->trigger_outval_selected, option, 
		sizeof(data->trigger_outval_selected));
}
// }}}

// {{{ cb_virtual_port_trigger_cnd_selector_activated()
G_MODULE_EXPORT void cb_virtual_port_trigger_cnd_selector_activated(
GtkWidget *w, virtual_selector_widgets_t *data)
{
	const char *option = gtk_menu_item_get_label(GTK_MENU_ITEM(w));
	strncpy(data->trigger_cnd_selected, option, 
		sizeof(data->trigger_cnd_selected));
}
// }}}


// {{{ virtual_port_menu_select()
void virtual_port_menu_select(virtual_selector_widgets_t *vsw, const char* txt)
{

	gtk_widget_destroy(vsw->item0);
	gtk_widget_destroy(vsw->item1);
	gtk_widget_destroy(vsw->item2);
	gtk_widget_destroy(vsw->item3);
	gtk_widget_destroy(vsw->menu);

	vsw->menu = gtk_menu_new();


	if(strcmp(txt, "Valor")==0)
	{
		vsw->item0 = gtk_menu_item_new_with_label ("Valor");
		vsw->item1 = gtk_menu_item_new_with_label ("Operación");
		vsw->item2 = gtk_menu_item_new_with_label ("Disparador");
		vsw->item3 = gtk_menu_item_new_with_label ("--");
	}

	else if(strcmp(txt, "Operación")==0)
	{
		vsw->item0 = gtk_menu_item_new_with_label ("Operación");
		vsw->item1 = gtk_menu_item_new_with_label ("Disparador");
		vsw->item2 = gtk_menu_item_new_with_label ("--");
		vsw->item3 = gtk_menu_item_new_with_label ("Valor");
	}

	else if(strcmp(txt, "Disparador")==0)
	{
		vsw->item0 = gtk_menu_item_new_with_label ("Disparador");
		vsw->item1 = gtk_menu_item_new_with_label ("--");
		vsw->item2 = gtk_menu_item_new_with_label ("Valor");
		vsw->item3 = gtk_menu_item_new_with_label ("Operación");
	}


	else if(strcmp(txt, "--")==0)
	{
		vsw->item0 = gtk_menu_item_new_with_label ("--");
		vsw->item1 = gtk_menu_item_new_with_label ("Valor");
		vsw->item2 = gtk_menu_item_new_with_label ("Operación");
		vsw->item3 = gtk_menu_item_new_with_label ("Disparador");
	}


	cb_virtual_port_selector_activated(vsw->item0, vsw);

	gtk_signal_connect(GTK_OBJECT(vsw->item0), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->item1), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->item2), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->item3), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_selector_activated), vsw);

	gtk_widget_show(vsw->item0);
	gtk_widget_show(vsw->item1);
	gtk_widget_show(vsw->item2);
	gtk_widget_show(vsw->item3);

	gtk_menu_append (GTK_MENU (vsw->menu), vsw->item0);
	gtk_menu_append (GTK_MENU (vsw->menu), vsw->item1);
	gtk_menu_append (GTK_MENU (vsw->menu), vsw->item2);
	gtk_menu_append (GTK_MENU (vsw->menu), vsw->item3);
	gtk_widget_show(vsw->menu);

	gtk_option_menu_set_menu(GTK_OPTION_MENU (vsw->opt), vsw->menu);

}
// }}}

// {{{ virtual_port_group_vp1_select()
void virtual_port_group_vp1_select(virtual_selector_widgets_t *vsw, 
	const char* txt)
{
	int i;

	for(i=0; i<32; i++)
		gtk_widget_destroy(vsw->group_vp1_item[i]);
	gtk_widget_destroy(vsw->group_vp1_menu);

	vsw->group_vp1_menu = gtk_menu_new();

	int j=0;
	for(i=0; i<8; i++)
		vsw->group_vp1_item[j++] = gtk_menu_item_new_with_label (p_di[i]);

	for(i=0; i<8; i++)
		vsw->group_vp1_item[j++] = gtk_menu_item_new_with_label (p_ai[i]);

	for(i=0; i<16; i++)
		vsw->group_vp1_item[j++] = gtk_menu_item_new_with_label (p_vt[i]);


	for(i=0; i<32; i++)
	{
		gtk_signal_connect(GTK_OBJECT(vsw->group_vp1_item[i]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_vp1_selector_activated), vsw);

		const char *lbl =  
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->group_vp1_item[i]));

		if(strcmp(txt, lbl)==0)
		{
			gtk_menu_append(GTK_MENU(vsw->group_vp1_menu),vsw->group_vp1_item[i]);
			cb_virtual_port_group_vp1_selector_activated(
				vsw->group_vp1_item[i], vsw);
		}
	}

	for(i=0; i<32; i++)
	{
		const char *lbl =  
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->group_vp1_item[i]));

		if(strcmp(txt, lbl)!=0)
			gtk_menu_append(GTK_MENU(vsw->group_vp1_menu),vsw->group_vp1_item[i]);

		gtk_widget_show(vsw->group_vp1_item[i]);
	}

	gtk_option_menu_set_menu(
		GTK_OPTION_MENU(vsw->group_vp1_opt), vsw->group_vp1_menu);
}
// }}}

// {{{ virtual_port_group_vp2_select()
void virtual_port_group_vp2_select(virtual_selector_widgets_t *vsw, 
	const char* txt)
{
	int i;

	for(i=0; i<32; i++)
		gtk_widget_destroy(vsw->group_vp2_item[i]);
	gtk_widget_destroy(vsw->group_vp2_menu);

	vsw->group_vp2_menu = gtk_menu_new();

	int j=0;
	for(i=0; i<8; i++)
		vsw->group_vp2_item[j++] = gtk_menu_item_new_with_label (p_di[i]);

	for(i=0; i<8; i++)
		vsw->group_vp2_item[j++] = gtk_menu_item_new_with_label (p_ai[i]);

	for(i=0; i<16; i++)
		vsw->group_vp2_item[j++] = gtk_menu_item_new_with_label (p_vt[i]);

	for(i=0; i<32; i++)
	{
		gtk_signal_connect(GTK_OBJECT(vsw->group_vp2_item[i]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_vp2_selector_activated), vsw);

		const char *lbl =  
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->group_vp2_item[i]));

		if(strcmp(txt, lbl)==0)
		{
			gtk_menu_append(GTK_MENU(vsw->group_vp2_menu),vsw->group_vp2_item[i]);
			cb_virtual_port_group_vp2_selector_activated(
				vsw->group_vp2_item[i], vsw);
		}
	}

	for(i=0; i<32; i++)
	{
		const char *lbl =  
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->group_vp2_item[i]));

		if(strcmp(txt, lbl)!=0)
			gtk_menu_append(GTK_MENU(vsw->group_vp2_menu),vsw->group_vp2_item[i]);

		gtk_widget_show(vsw->group_vp2_item[i]);
	}

	gtk_option_menu_set_menu(
		GTK_OPTION_MENU(vsw->group_vp2_opt), vsw->group_vp2_menu);
}
// }}}

// {{{ virtual_port_group_op_select()
void virtual_port_group_op_select(virtual_selector_widgets_t *vsw, 
	const char* txt)
{
	gtk_widget_destroy(vsw->group_op_item1);
	gtk_widget_destroy(vsw->group_op_item2);
	gtk_widget_destroy(vsw->group_op_item3);
	gtk_widget_destroy(vsw->group_op_item4);
	gtk_widget_destroy(vsw->group_op_menu);

	vsw->group_op_menu = gtk_menu_new();

	vsw->group_op_item1 = gtk_menu_item_new_with_label ("+");
	vsw->group_op_item2 = gtk_menu_item_new_with_label ("-");
	vsw->group_op_item3 = gtk_menu_item_new_with_label ("&");
	vsw->group_op_item4 = gtk_menu_item_new_with_label ("|");


	gtk_signal_connect(GTK_OBJECT(vsw->group_op_item1), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_op_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->group_op_item2), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_op_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->group_op_item3), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_op_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->group_op_item4), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_op_selector_activated), vsw);

	const char *item1 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->group_op_item1));
	const char *item2 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->group_op_item2));
	const char *item3 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->group_op_item3));
	const char *item4 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->group_op_item4));

	if(strcmp(item1, txt)==0)
	{
		cb_virtual_port_group_op_selector_activated(vsw->group_op_item1, vsw);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item1);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item2);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item3);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item4);
	}
		
	else if(strcmp(item2, txt)==0)
	{
		cb_virtual_port_group_op_selector_activated(vsw->group_op_item2, vsw);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item2);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item3);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item4);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item1);
	}
		
	else if(strcmp(item3, txt)==0)
	{
		cb_virtual_port_group_op_selector_activated(vsw->group_op_item3, vsw);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item3);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item4);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item1);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item2);
	}
	
	else if(strcmp(item4, txt)==0)
	{
		cb_virtual_port_group_op_selector_activated(vsw->group_op_item4, vsw);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item4);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item1);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item2);
		gtk_menu_append(GTK_MENU(vsw->group_op_menu),vsw->group_op_item3);
	}
	

	gtk_widget_show(vsw->group_op_item1);
	gtk_widget_show(vsw->group_op_item2);
	gtk_widget_show(vsw->group_op_item3);
	gtk_widget_show(vsw->group_op_item4);

	gtk_option_menu_set_menu(
		GTK_OPTION_MENU(vsw->group_op_opt), vsw->group_op_menu);
}
// }}}

// {{{ virtual_port_value_ad_select()
void virtual_port_value_ad_select(virtual_selector_widgets_t *vsw, 
	const char* txt)
{
	gtk_widget_destroy(vsw->value_ad_item1);
	gtk_widget_destroy(vsw->value_ad_item2);
	gtk_widget_destroy(vsw->value_ad_menu);

	vsw->value_ad_menu = gtk_menu_new();

	vsw->value_ad_item1 = gtk_menu_item_new_with_label ("Digital");
	vsw->value_ad_item2 = gtk_menu_item_new_with_label ("Analógico");

	gtk_signal_connect(GTK_OBJECT(vsw->value_ad_item1), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_value_ad_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->value_ad_item2), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_value_ad_selector_activated), vsw);

	const char *item1 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->value_ad_item1));
	const char *item2 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->value_ad_item2));

	if(strcmp(item1, txt)==0)
	{
		cb_virtual_port_value_ad_selector_activated(vsw->value_ad_item1, vsw);
		gtk_menu_append(GTK_MENU(vsw->value_ad_menu),vsw->value_ad_item1);
		gtk_menu_append(GTK_MENU(vsw->value_ad_menu),vsw->value_ad_item2);
	}
		
	else if(strcmp(item2, txt)==0)
	{
		cb_virtual_port_value_ad_selector_activated(vsw->value_ad_item2, vsw);
		gtk_menu_append(GTK_MENU(vsw->value_ad_menu),vsw->value_ad_item2);
		gtk_menu_append(GTK_MENU(vsw->value_ad_menu),vsw->value_ad_item1);
	}
		

	gtk_widget_show(vsw->value_ad_item1);
	gtk_widget_show(vsw->value_ad_item2);

	gtk_option_menu_set_menu(
		GTK_OPTION_MENU(vsw->value_ad_opt), vsw->value_ad_menu);
}
// }}}

// {{{ virtual_port_trigger_cndp_select()
void virtual_port_trigger_cndp_select(virtual_selector_widgets_t *vsw, 
	const char* txt)
{
	int i;

	for(i=0; i<32; i++)
		gtk_widget_destroy(vsw->trigger_cndp_item[i]);
	gtk_widget_destroy(vsw->trigger_cndp_menu);

	vsw->trigger_cndp_menu = gtk_menu_new();

	int j=0;
	for(i=0; i<8; i++)
		vsw->trigger_cndp_item[j++] = gtk_menu_item_new_with_label (p_di[i]);

	for(i=0; i<8; i++)
		vsw->trigger_cndp_item[j++] = gtk_menu_item_new_with_label (p_ai[i]);

	for(i=0; i<16; i++)
		vsw->trigger_cndp_item[j++] = gtk_menu_item_new_with_label (p_vt[i]);

	for(i=0; i<32; i++)
	{
		const char *lbl =  
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_cndp_item[i]));

		if(strcmp(txt, lbl)==0)
		{
			gtk_menu_append(GTK_MENU(vsw->trigger_cndp_menu),
				vsw->trigger_cndp_item[i]);

			cb_virtual_port_trigger_cndp_selector_activated(
				vsw->trigger_cndp_item[i], vsw);
		}
	}

	for(i=0; i<32; i++)
	{
		gtk_signal_connect(GTK_OBJECT(vsw->trigger_cndp_item[i]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cndp_selector_activated), vsw);

		const char *lbl =  
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_cndp_item[i]));

		if(strcmp(txt, lbl)!=0)
			gtk_menu_append(GTK_MENU(vsw->trigger_cndp_menu),
				vsw->trigger_cndp_item[i]);

		gtk_widget_show(vsw->trigger_cndp_item[i]);
	}

	gtk_option_menu_set_menu(
		GTK_OPTION_MENU(vsw->trigger_cndp_opt), vsw->trigger_cndp_menu);
}
// }}}

// {{{ virtual_port_trigger_outp_select()
void virtual_port_trigger_outp_select(virtual_selector_widgets_t *vsw, 
	const char* txt)
{
	int i;

	for(i=0; i<8; i++)
		gtk_widget_destroy(vsw->trigger_outp_item[i]);
	gtk_widget_destroy(vsw->trigger_outp_menu);

	vsw->trigger_outp_menu = gtk_menu_new();

	int j=0;
	for(i=0; i<8; i++)
		vsw->trigger_outp_item[j++] = gtk_menu_item_new_with_label (p_do[i]);

	for(i=0; i<8; i++)
	{
		gtk_signal_connect(GTK_OBJECT(vsw->trigger_outp_item[i]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_outp_selector_activated), vsw);

		const char *lbl =  
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_outp_item[i]));

		if(strcmp(txt, lbl)==0)
		{
			gtk_menu_append(GTK_MENU(vsw->trigger_outp_menu),
				vsw->trigger_outp_item[i]);

			cb_virtual_port_trigger_outp_selector_activated(
				vsw->trigger_outp_item[i], vsw);
		}
	}

	for(i=0; i<8; i++)
	{
		const char *lbl =  
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_outp_item[i]));

		if(strcmp(txt, lbl)!=0)
			gtk_menu_append(GTK_MENU(vsw->trigger_outp_menu),
				vsw->trigger_outp_item[i]);

		gtk_widget_show(vsw->trigger_outp_item[i]);
	}

	gtk_option_menu_set_menu(
		GTK_OPTION_MENU(vsw->trigger_outp_opt), vsw->trigger_outp_menu);
}
// }}}

// {{{ virtual_port_trigger_cnd_select()
void virtual_port_trigger_cnd_select(virtual_selector_widgets_t *vsw, 
	const char* txt)
{
	gtk_widget_destroy(vsw->trigger_cnd_item1);
	gtk_widget_destroy(vsw->trigger_cnd_item2);
	gtk_widget_destroy(vsw->trigger_cnd_item3);
	gtk_widget_destroy(vsw->trigger_cnd_item4);
	gtk_widget_destroy(vsw->trigger_cnd_item5);
	gtk_widget_destroy(vsw->trigger_cnd_item6);
	gtk_widget_destroy(vsw->trigger_cnd_menu);

	vsw->trigger_cnd_menu = gtk_menu_new();

	vsw->trigger_cnd_item1 = gtk_menu_item_new_with_label ("==");
	vsw->trigger_cnd_item2 = gtk_menu_item_new_with_label ("!=");
	vsw->trigger_cnd_item3 = gtk_menu_item_new_with_label ("<=");
	vsw->trigger_cnd_item4 = gtk_menu_item_new_with_label (">=");
	vsw->trigger_cnd_item5 = gtk_menu_item_new_with_label (" <");
	vsw->trigger_cnd_item6 = gtk_menu_item_new_with_label (" >");

	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item1), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item2), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item3), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item4), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item5), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item6), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);



	const char *item1 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_cnd_item1));
	const char *item2 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_cnd_item2));
	const char *item3 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_cnd_item3));
	const char *item4 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_cnd_item4));
	const char *item5 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_cnd_item5));
	const char *item6 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_cnd_item6));

	if(strcmp(item1, txt)==0)
	{
		cb_virtual_port_trigger_cnd_selector_activated(
			vsw->trigger_cnd_item1, vsw);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item1);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item2);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item3);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item4);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item5);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item6);
	}
		
	else if(strcmp(item2, txt)==0)
	{
		cb_virtual_port_trigger_cnd_selector_activated(
			vsw->trigger_cnd_item2, vsw);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item2);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item3);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item4);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item5);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item6);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item1);
	}
		
	else if(strcmp(item3, txt)==0)
	{
		cb_virtual_port_trigger_cnd_selector_activated(
			vsw->trigger_cnd_item3, vsw);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item3);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item4);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item5);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item6);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item1);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item2);
	}
	
	else if(strcmp(item4, txt)==0)
	{
		cb_virtual_port_trigger_cnd_selector_activated(
			vsw->trigger_cnd_item4, vsw);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item4);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item5);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item6);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item1);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item2);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item3);
	}
		
	else if(strcmp(item5, txt)==0)
	{
		cb_virtual_port_trigger_cnd_selector_activated(
			vsw->trigger_cnd_item5, vsw);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item5);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item6);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item1);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item2);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item3);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item4);
	}
	
	else if(strcmp(item6, txt)==0)
	{
		cb_virtual_port_trigger_cnd_selector_activated(
			vsw->trigger_cnd_item6, vsw);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item6);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item1);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item2);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item3);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item4);
		gtk_menu_append(GTK_MENU(vsw->trigger_cnd_menu),vsw->trigger_cnd_item5);
	}

	gtk_widget_show(vsw->trigger_cnd_item1);
	gtk_widget_show(vsw->trigger_cnd_item2);
	gtk_widget_show(vsw->trigger_cnd_item3);
	gtk_widget_show(vsw->trigger_cnd_item4);
	gtk_widget_show(vsw->trigger_cnd_item5);
	gtk_widget_show(vsw->trigger_cnd_item6);

	gtk_option_menu_set_menu(
		GTK_OPTION_MENU(vsw->trigger_cnd_opt), vsw->trigger_cnd_menu);
}
// }}}

// {{{ virtual_port_trigger_outval_select()
void virtual_port_trigger_outval_select(virtual_selector_widgets_t *vsw, 
	const char* txt)
{

	gtk_widget_destroy(vsw->trigger_outval_item1);
	gtk_widget_destroy(vsw->trigger_outval_item2);
	gtk_widget_destroy(vsw->trigger_outval_menu);

	vsw->trigger_outval_menu = gtk_menu_new();

	vsw->trigger_outval_item1 = gtk_menu_item_new_with_label ("on");
	vsw->trigger_outval_item2 = gtk_menu_item_new_with_label ("off");

	gtk_signal_connect(GTK_OBJECT(vsw->trigger_outval_item1), "activate", 
		GTK_SIGNAL_FUNC(cb_virtual_port_trigger_outval_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_outval_item2), "activate", 
		GTK_SIGNAL_FUNC(cb_virtual_port_trigger_outval_selector_activated), vsw);

	const char *item1 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_outval_item1));
	const char *item2 = 
			gtk_menu_item_get_label(GTK_MENU_ITEM(vsw->trigger_outval_item2));

	if(strcmp(item1, txt)==0)
	{
		cb_virtual_port_trigger_outval_selector_activated(
			vsw->trigger_outval_item1, vsw);
		gtk_menu_append(GTK_MENU(vsw->trigger_outval_menu),
			vsw->trigger_outval_item1);
		gtk_menu_append(GTK_MENU(vsw->trigger_outval_menu),
			vsw->trigger_outval_item2);
	}
		
	else if(strcmp(item2, txt)==0)
	{
		cb_virtual_port_trigger_outval_selector_activated(
			vsw->trigger_outval_item2, vsw);
		gtk_menu_append(GTK_MENU(vsw->trigger_outval_menu),
			vsw->trigger_outval_item2);
		gtk_menu_append(GTK_MENU(vsw->trigger_outval_menu),
			vsw->trigger_outval_item1);
	}

	gtk_widget_show(vsw->trigger_outval_item1);
	gtk_widget_show(vsw->trigger_outval_item2);

	gtk_option_menu_set_menu(
		GTK_OPTION_MENU(vsw->trigger_outval_opt), vsw->trigger_outval_menu);
}
// }}}

// {{{ virtual_port_widgets_create()
void virtual_port_widgets_create(
	virtual_selector_widgets_t *vsw, GtkWidget *parent, int x, int y)
{
   vsw->opt = gtk_option_menu_new();
   vsw->menu = gtk_menu_new();
   
	// -- NONE --
	vsw->item0 = gtk_menu_item_new_with_label ("--");
   gtk_signal_connect(GTK_OBJECT(vsw->item0), "activate", 
		GTK_SIGNAL_FUNC(cb_virtual_port_selector_activated), vsw);
	gtk_widget_show(vsw->item0);
   gtk_menu_append (GTK_MENU (vsw->menu), vsw->item0);


	// -- VALUE --
	vsw->item1 = gtk_menu_item_new_with_label ("Valor");
   gtk_signal_connect(GTK_OBJECT(vsw->item1), "activate", 
		GTK_SIGNAL_FUNC(cb_virtual_port_selector_activated), vsw);
	gtk_widget_show(vsw->item1);
   gtk_menu_append (GTK_MENU (vsw->menu), vsw->item1);

   vsw->value_ad_opt = gtk_option_menu_new();
   vsw->value_ad_menu = gtk_menu_new();
   vsw->value_ad_item1 = gtk_menu_item_new_with_label ("Digital");
   vsw->value_ad_item2 = gtk_menu_item_new_with_label ("Analógico");
	cb_virtual_port_value_ad_selector_activated(vsw->value_ad_item1, vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->value_ad_item1), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_value_ad_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->value_ad_item2), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_value_ad_selector_activated), vsw);
	gtk_widget_show(vsw->value_ad_item1);
	gtk_widget_show(vsw->value_ad_item2);
   gtk_menu_append (GTK_MENU (vsw->value_ad_menu), vsw->value_ad_item1);
   gtk_menu_append (GTK_MENU (vsw->value_ad_menu), vsw->value_ad_item2);
   gtk_option_menu_set_menu 
		(GTK_OPTION_MENU (vsw->value_ad_opt), vsw->value_ad_menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->value_ad_opt, x+215, y);

	vsw->entry_v_value = gtk_entry_new();
	gtk_entry_set_width_chars(GTK_ENTRY(vsw->entry_v_value), 10);
	gtk_entry_set_max_length(GTK_ENTRY(vsw->entry_v_value), 10);
	gtk_fixed_put (GTK_FIXED(parent), vsw->entry_v_value, x+335, y); 

	// -- GROUP --
   vsw->item2 = gtk_menu_item_new_with_label ("Operación");
   gtk_signal_connect(GTK_OBJECT(vsw->item2), "activate", 
		GTK_SIGNAL_FUNC(cb_virtual_port_selector_activated), vsw);
	gtk_widget_show(vsw->item2);
   gtk_menu_append (GTK_MENU (vsw->menu), vsw->item2);

   vsw->group_vp1_opt = gtk_option_menu_new();
   vsw->group_vp1_menu = gtk_menu_new();
	int i;
	for(i=0; i<8; i++)
	{
   	vsw->group_vp1_item[i] = gtk_menu_item_new_with_label (p_di[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->group_vp1_item[i]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_vp1_selector_activated), vsw);
		gtk_widget_show(vsw->group_vp1_item[i]);
   	gtk_menu_append (GTK_MENU (vsw->group_vp1_menu), vsw->group_vp1_item[i]);
	}
	cb_virtual_port_group_vp1_selector_activated(vsw->group_vp1_item[0], vsw);
	for(i=0; i<8; i++)
	{
   	vsw->group_vp1_item[i+8] = gtk_menu_item_new_with_label (p_ai[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->group_vp1_item[i+8]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_vp1_selector_activated), vsw);
		gtk_widget_show(vsw->group_vp1_item[i+8]);
   	gtk_menu_append(GTK_MENU (vsw->group_vp1_menu), vsw->group_vp1_item[i+8]);
	}
	for(i=0; i<16; i++)
	{
   	vsw->group_vp1_item[i+16] = gtk_menu_item_new_with_label (p_vt[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->group_vp1_item[i+16]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_vp1_selector_activated), vsw);
		gtk_widget_show(vsw->group_vp1_item[i+16]);
   	gtk_menu_append(GTK_MENU (vsw->group_vp1_menu),vsw->group_vp1_item[i+16]);
	}

   gtk_option_menu_set_menu 
		(GTK_OPTION_MENU (vsw->group_vp1_opt), vsw->group_vp1_menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->group_vp1_opt, x+215, y);

   vsw->group_vp2_opt = gtk_option_menu_new();
   vsw->group_vp2_menu = gtk_menu_new();
	for(i=0; i<8; i++)
	{
   	vsw->group_vp2_item[i] = gtk_menu_item_new_with_label (p_di[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->group_vp2_item[i]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_vp2_selector_activated), vsw);
		gtk_widget_show(vsw->group_vp2_item[i]);
   	gtk_menu_append (GTK_MENU (vsw->group_vp2_menu), vsw->group_vp2_item[i]);
	}
	cb_virtual_port_group_vp2_selector_activated(vsw->group_vp2_item[0], vsw);
	for(i=0; i<8; i++)
	{
   	vsw->group_vp2_item[i+8] = gtk_menu_item_new_with_label (p_ai[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->group_vp2_item[i+8]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_vp2_selector_activated), vsw);
		gtk_widget_show(vsw->group_vp2_item[i+8]);
   	gtk_menu_append(GTK_MENU (vsw->group_vp2_menu), vsw->group_vp2_item[i+8]);
	}
	for(i=0; i<16; i++)
	{
   	vsw->group_vp2_item[i+16] = gtk_menu_item_new_with_label (p_vt[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->group_vp2_item[i+16]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_vp2_selector_activated), vsw);
		gtk_widget_show(vsw->group_vp2_item[i+16]);
   	gtk_menu_append(GTK_MENU (vsw->group_vp2_menu),vsw->group_vp2_item[i+16]);
	}

   gtk_option_menu_set_menu 
		(GTK_OPTION_MENU (vsw->group_vp2_opt), vsw->group_vp2_menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->group_vp2_opt, x+355, y);


   vsw->group_op_opt = gtk_option_menu_new();
   vsw->group_op_menu = gtk_menu_new();
   vsw->group_op_item1 = gtk_menu_item_new_with_label ("+");
   vsw->group_op_item2 = gtk_menu_item_new_with_label ("-");
   vsw->group_op_item3 = gtk_menu_item_new_with_label ("|");
   vsw->group_op_item4 = gtk_menu_item_new_with_label ("&");
	cb_virtual_port_group_op_selector_activated(vsw->group_op_item1, vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->group_op_item1), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_op_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->group_op_item2), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_op_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->group_op_item3), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_op_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->group_op_item4), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_group_op_selector_activated), vsw);
	gtk_widget_show(vsw->group_op_item1);
	gtk_widget_show(vsw->group_op_item2);
	gtk_widget_show(vsw->group_op_item3);
	gtk_widget_show(vsw->group_op_item4);
   gtk_menu_append (GTK_MENU (vsw->group_op_menu), vsw->group_op_item1);
   gtk_menu_append (GTK_MENU (vsw->group_op_menu), vsw->group_op_item2);
   gtk_menu_append (GTK_MENU (vsw->group_op_menu), vsw->group_op_item3);
   gtk_menu_append (GTK_MENU (vsw->group_op_menu), vsw->group_op_item4);
   gtk_option_menu_set_menu (GTK_OPTION_MENU (vsw->group_op_opt), vsw->group_op_menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->group_op_opt, x+300, y);



	// -- TRIGGER --
   vsw->item3 = gtk_menu_item_new_with_label ("Disparador");
   gtk_signal_connect(GTK_OBJECT(vsw->item3), "activate", 
		GTK_SIGNAL_FUNC(cb_virtual_port_selector_activated), vsw);
	gtk_widget_show(vsw->item3);
   gtk_menu_append (GTK_MENU (vsw->menu), vsw->item3);


   vsw->trigger_cnd_opt = gtk_option_menu_new();
   vsw->trigger_cnd_menu = gtk_menu_new();
   vsw->trigger_cnd_item1 = gtk_menu_item_new_with_label ("==");
   vsw->trigger_cnd_item2 = gtk_menu_item_new_with_label ("<=");
   vsw->trigger_cnd_item3 = gtk_menu_item_new_with_label (">=");
   vsw->trigger_cnd_item4 = gtk_menu_item_new_with_label (" <");
   vsw->trigger_cnd_item5 = gtk_menu_item_new_with_label (" >");
   vsw->trigger_cnd_item6 = gtk_menu_item_new_with_label ("!=");
	cb_virtual_port_group_op_selector_activated(vsw->trigger_cnd_item1, vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item1), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item2), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item3), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item4), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item5), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_cnd_item6), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cnd_selector_activated), vsw);
	gtk_widget_show(vsw->trigger_cnd_item1);
	gtk_widget_show(vsw->trigger_cnd_item2);
	gtk_widget_show(vsw->trigger_cnd_item3);
	gtk_widget_show(vsw->trigger_cnd_item4);
	gtk_widget_show(vsw->trigger_cnd_item5);
	gtk_widget_show(vsw->trigger_cnd_item6);
   gtk_menu_append (GTK_MENU (vsw->trigger_cnd_menu), vsw->trigger_cnd_item1);
   gtk_menu_append (GTK_MENU (vsw->trigger_cnd_menu), vsw->trigger_cnd_item2);
   gtk_menu_append (GTK_MENU (vsw->trigger_cnd_menu), vsw->trigger_cnd_item3);
   gtk_menu_append (GTK_MENU (vsw->trigger_cnd_menu), vsw->trigger_cnd_item4);
   gtk_menu_append (GTK_MENU (vsw->trigger_cnd_menu), vsw->trigger_cnd_item5);
   gtk_menu_append (GTK_MENU (vsw->trigger_cnd_menu), vsw->trigger_cnd_item6);
   gtk_option_menu_set_menu (GTK_OPTION_MENU (vsw->trigger_cnd_opt), vsw->trigger_cnd_menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->trigger_cnd_opt, x+215, y);


   vsw->trigger_cndp_opt = gtk_option_menu_new();
   vsw->trigger_cndp_menu = gtk_menu_new();
	for(i=0; i<8; i++)
	{
   	vsw->trigger_cndp_item[i] = gtk_menu_item_new_with_label (p_di[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->trigger_cndp_item[i]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cndp_selector_activated), vsw);
		gtk_widget_show(vsw->trigger_cndp_item[i]);
   	gtk_menu_append 
			(GTK_MENU (vsw->trigger_cndp_menu), vsw->trigger_cndp_item[i]);
	}
	cb_virtual_port_trigger_cndp_selector_activated(
		vsw->trigger_cndp_item[0], vsw);
	for(i=0; i<8; i++)
	{
   	vsw->trigger_cndp_item[i+8] = gtk_menu_item_new_with_label (p_ai[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->trigger_cndp_item[i+8]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cndp_selector_activated), vsw);
		gtk_widget_show(vsw->trigger_cndp_item[i+8]);
   	gtk_menu_append	
			(GTK_MENU (vsw->trigger_cndp_menu), vsw->trigger_cndp_item[i+8]);
	}
	for(i=0; i<16; i++)
	{
   	vsw->trigger_cndp_item[i+16] = gtk_menu_item_new_with_label (p_vt[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->trigger_cndp_item[i+16]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_cndp_selector_activated), vsw);
		gtk_widget_show(vsw->trigger_cndp_item[i+16]);
   	gtk_menu_append
			(GTK_MENU (vsw->trigger_cndp_menu),vsw->trigger_cndp_item[i+16]);
	}

   gtk_option_menu_set_menu 
		(GTK_OPTION_MENU (vsw->trigger_cndp_opt), vsw->trigger_cndp_menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->trigger_cndp_opt, x+275, y);



   vsw->trigger_outp_opt = gtk_option_menu_new();
   vsw->trigger_outp_menu = gtk_menu_new();
	for(i=0; i<8; i++)
	{
   	vsw->trigger_outp_item[i] = gtk_menu_item_new_with_label(p_do[i]);
		gtk_signal_connect(GTK_OBJECT(vsw->trigger_outp_item[i]), "activate", 
			GTK_SIGNAL_FUNC(cb_virtual_port_trigger_outp_selector_activated), vsw);
		gtk_widget_show(vsw->trigger_outp_item[i]);
   	gtk_menu_append 
			(GTK_MENU (vsw->trigger_outp_menu), vsw->trigger_outp_item[i]);
	}
	cb_virtual_port_trigger_outp_selector_activated(
		vsw->trigger_outp_item[0], vsw);

   gtk_option_menu_set_menu 
		(GTK_OPTION_MENU (vsw->trigger_outp_opt), vsw->trigger_outp_menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->trigger_outp_opt, x+370, y);



   vsw->trigger_outval_opt = gtk_option_menu_new();
   vsw->trigger_outval_menu = gtk_menu_new();
   vsw->trigger_outval_item1 = gtk_menu_item_new_with_label ("on");
   vsw->trigger_outval_item2 = gtk_menu_item_new_with_label ("off");
	cb_virtual_port_trigger_outval_selector_activated(
		vsw->trigger_outval_item1, vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_outval_item1), "activate", 
		GTK_SIGNAL_FUNC(cb_virtual_port_trigger_outval_selector_activated), vsw);
	gtk_signal_connect(GTK_OBJECT(vsw->trigger_outval_item2), "activate", 
		GTK_SIGNAL_FUNC(cb_virtual_port_trigger_outval_selector_activated), vsw);
	gtk_widget_show(vsw->trigger_outval_item1);
	gtk_widget_show(vsw->trigger_outval_item2);
   gtk_menu_append
		(GTK_MENU (vsw->trigger_outval_menu), vsw->trigger_outval_item1);
   gtk_menu_append
		(GTK_MENU (vsw->trigger_outval_menu), vsw->trigger_outval_item2);
   gtk_option_menu_set_menu
		(GTK_OPTION_MENU(vsw->trigger_outval_opt),vsw->trigger_outval_menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->trigger_outval_opt, x+450, y);


   gtk_option_menu_set_menu (GTK_OPTION_MENU (vsw->opt), vsw->menu);
	gtk_fixed_put (GTK_FIXED(parent), vsw->opt, x+90, y);
   gtk_widget_show (vsw->opt);

}
// }}}}


